varying vec3 v_ScreenPos;
varying vec3 v_Pos;

varying vec3 v_ViewVecInView;
varying vec3 v_NormalInView;
varying vec3 v_NormalInWorld;
varying vec3 v_TangentInWorld;

uniform float u_WaveTime;

void main()
{
	vec4 Position=gl_Vertex;
	
	vec2  D0=normalize(vec2(-3, 3)-Position.xy);
	float A0=0.05;
	float w0=1;
	float S0=0.5;
	
	vec2  D1=normalize(vec2(5, 14)-Position.xy);
	float A1=0.04;
	float w1=2.3;
	float S1=1;
	
	
	vec2  D2=normalize(vec2(-8, 9)-Position.xy);
	float A2=0.06;
	float w2=1.3;
	float S2=0.837;
	
	vec2  D3=normalize(vec2(6, -1)-Position.xy);
	float A3=0.03;
	float w3=0.9;
	float S3=2.337;
	
	Position.z=	 A0*sin(dot(D0, vec2(Position.x, Position.y))*w0+u_WaveTime*S0)
				+A1*sin(dot(D1, vec2(Position.x, Position.y))*w1+u_WaveTime*S1)
				+A2*sin(dot(D2, vec2(Position.x, Position.y))*w2+u_WaveTime*S2)
				+A3*sin(dot(D3, vec2(Position.x, Position.y))*w3+u_WaveTime*S3);
	
	vec3 Normal=normalize(vec3(
			-w0*D0.x*A0*cos(dot(D0, vec2(Position.x, Position.y))*w0+u_WaveTime*S0)+
			-w1*D1.x*A1*cos(dot(D1, vec2(Position.x, Position.y))*w1+u_WaveTime*S1)+
			-w2*D2.x*A2*cos(dot(D2, vec2(Position.x, Position.y))*w2+u_WaveTime*S2)+
			-w3*D3.x*A3*cos(dot(D2, vec2(Position.x, Position.y))*w3+u_WaveTime*S3),
			
			-w0*D0.y*A0*cos(dot(D0, vec2(Position.x, Position.y))*w0+u_WaveTime*S0)+
			-w1*D1.y*A1*cos(dot(D1, vec2(Position.x, Position.y))*w1+u_WaveTime*S1)+
			-w2*D2.y*A2*cos(dot(D2, vec2(Position.x, Position.y))*w2+u_WaveTime*S2)+
			-w3*D3.y*A3*cos(dot(D3, vec2(Position.x, Position.y))*w3+u_WaveTime*S3),
			
			1));
	
	vec3 Tangent=normalize(vec3(0, 1,
			w0*D0.y*A0*cos(dot(D0, vec2(Position.x, Position.y))*w0+u_WaveTime*S0)+
			w1*D1.y*A1*cos(dot(D1, vec2(Position.x, Position.y))*w1+u_WaveTime*S1)+
			w2*D2.y*A2*cos(dot(D2, vec2(Position.x, Position.y))*w2+u_WaveTime*S2)+
			w3*D3.y*A3*cos(dot(D3, vec2(Position.x, Position.y))*w3+u_WaveTime*S3)			
			));

	v_ViewVecInView=normalize((gl_ModelViewMatrix*Position).xyz);
	v_NormalInWorld=Normal;
	v_TangentInWorld=Tangent;
	v_NormalInView=normalize(gl_NormalMatrix*Normal);
	
	v_Pos=Position.xyz;
	gl_Position=gl_ModelViewProjectionMatrix*Position;
	v_ScreenPos=(gl_ModelViewProjectionMatrix*Position).xyw;
	
}